package com.ruoyi.edge.gateway.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.edge.gateway.domain.CollectSource;
import com.ruoyi.edge.gateway.mapper.CollectSourceMapper;
import com.ruoyi.edge.gateway.service.CollectSourceService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 采集数据源
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class CollectSourceServiceImpl implements CollectSourceService {

    private final CollectSourceMapper collectSourceMapper;

    @Override
    public TableDataInfo<CollectSource> listPage(CollectSource collectSource, PageQuery pageQuery) {

        LambdaQueryWrapper<CollectSource> lqw = new LambdaQueryWrapper<>();
        Page<CollectSource> page = collectSourceMapper.selectPage(pageQuery.build(), lqw);
        return TableDataInfo.build(page);
    }

    @Override
    public R<List<CollectSource>> list(CollectSource collectSource) {
        LambdaQueryWrapper<CollectSource> lqw = new LambdaQueryWrapper<>();
        List<CollectSource> collectSources = collectSourceMapper.selectList(lqw);
        return R.ok(collectSources);
    }


    @Override
    public R<CollectSource> get(String id) {
        CollectSource collectSource = collectSourceMapper.selectById(id);
        return R.ok(collectSource);
    }

    @Override
    public R<String> add(CollectSource collectSource) {
        collectSourceMapper.insert(collectSource);
        return R.ok("新增成功");
    }

    @Override
    public R<String> edit(CollectSource collectSource) {
        collectSourceMapper.updateById(collectSource);
        return R.ok("修改成功");
    }

    @Override
    public R<String> remove(String id) {
        collectSourceMapper.deleteById(id);
        return R.ok("删除成功");
    }

}
